#include"comm.hpp"
int main()
{
    bool r=createFifo(NAMED_PIPE);
    assert(r);
    (void)r;

    cout<<"Server begin :"<<endl;
    int rfd=open(NAMED_PIPE,O_RDONLY);
    if(rfd<0) exit(1); //文件打开失败
    

    char buffer[1024];
    while(true)
    {
        ssize_t s=read(rfd,buffer,sizeof(buffer)-1);
        if(s>0)
        {
            buffer[s]=0;
            cout<<"client->server# "<<buffer;
        }
        else if(s==0)
        {
            cout<<"client quit, so server quit too!"<<endl;
            break;
        }
        else
        {
            cout<<"err string: "<<strerror(errno)<<endl;
            break;
        }
    }

    close(rfd);
    removeFifo(NAMED_PIPE);
    
    return 0;
}

